package com.pactera.madp.cp.service.sync.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pactera.madp.cp.api.entity.sync.MaYesterdayDataBoardEntity;
import com.pactera.madp.cp.api.entity.sync.MaTodayDataBoardEntity;
import com.pactera.madp.cp.api.entity.sync.SyncEventEntity;
import com.pactera.madp.cp.mapper.sync.SyncEventMapper;
import com.pactera.madp.cp.service.sync.SyncEventService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 行为采集事件
 *
 * @author Deming.Chang
 * @date 2022-05-11
 */
@Service
public class SyncEventServiceImpl extends ServiceImpl<SyncEventMapper, SyncEventEntity> implements SyncEventService {

    @Override
    public List<MaTodayDataBoardEntity> getRecommendBoard(String date) {
        return baseMapper.countByDate(date);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countThreeDate(String beginDate, String endDate) {
        return baseMapper.countByThreeDate(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countSevenDate(String beginDate, String endDate) {
        return baseMapper.countBySevenDate(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countThreeDateFinancial(String beginDate, String endDate) {
        return baseMapper.countByThreeDateFinancial(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countSevenDateFinancial(String beginDate, String endDate) {
        return baseMapper.countBySevenDateFinancial(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countThreeDateFund(String beginDate, String endDate) {
        return baseMapper.countByThreeDateFund(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countSevenDateFund(String beginDate, String endDate) {
        return baseMapper.countBySevenDateFund(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countThreeDateDeposit(String beginDate, String endDate) {
        return baseMapper.countByThreeDateDeposit(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countSevenDateDeposit(String beginDate, String endDate) {
        return baseMapper.countBySevenDateDeposit(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countThreeDateLoan(String beginDate, String endDate) {
        return baseMapper.countByThreeDateLoan(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countSevenDateLoan(String beginDate, String endDate) {
        return baseMapper.countBySevenDateLoan(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countThreeDateCredit(String beginDate, String endDate) {
        return baseMapper.countByThreeDateCredit(beginDate, endDate);
    }

    @Override
    public List<MaYesterdayDataBoardEntity> countSevenDateCredit(String beginDate, String endDate) {
        return baseMapper.countBySevenDateCredit(beginDate, endDate);
    }

    @Override
    public Long getOneLastMaxReceiveTime() {
        Long lastMaxReceiveTime = baseMapper.selectOneLastMaxReceiveTime();
        if(ObjectUtil.isNull(lastMaxReceiveTime)){
            // 首次批量数据未同步，默认获取当前时间半小时之前的时间戳
            return System.currentTimeMillis() - (30 * 60 * 1000);
        }
        return lastMaxReceiveTime;
    }

}
